//
//  LottoViewController.m
//  KG
//
//  Created by Eugene Braginets on 17.03.12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "LottoViewController.h"
#import "bannerView.h"

@implementation LottoViewController
@synthesize activityIndicator;
@synthesize webView;
@synthesize bannerViewController=_bannerViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    NSURL* url=[NSURL URLWithString:@"http://www.kerrygaa.ie/a_get_content.php?lid=GAA1_1_13668fe75b1a7dd6"]; 
    NSURLRequest* request=[NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    [self.webView setOpaque:NO];
    [self.webView setBackgroundColor:[UIColor clearColor]];
    [self.webView setHidden:YES];
    [self.activityIndicator startAnimating];
    
    bannerView *bannerVC=[[bannerView alloc] init];
    [self.view addSubview:bannerVC.view];
    [bannerVC animate];
    self.bannerViewController=bannerVC;
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload {
    [self setWebView:nil];
    [self setActivityIndicator:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)viewWillDisappear:(BOOL)animated {
    
    [self.webView stopLoading];
    self.webView.delegate = nil;
    [super viewWillDisappear:animated];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - WebView Delegate Methods

- (void)webViewDidStartLoad:(UIWebView *)webView {
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    //  self.careerWebView.frame = CGRectMake(320, 10, 315, 350);
    self.webView.alpha=0;
    self.webView.hidden = NO;
    [UIView animateWithDuration:0.4 animations:^{
        //        self.careerWebView.frame = CGRectMake(0, 10, 315, 350);
        self.webView.alpha=1;
    }];
    
    [self.activityIndicator setHidden:YES];
    
}

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
   
    NSRange range=[[[request URL] absoluteString] rangeOfString:@"locallotto.ie"];
    if (range.location!=NSNotFound){
        [[UIApplication sharedApplication] openURL:[request URL]];
        
        return NO;
    }
        return YES;
}
@end
